//
//  ViewController.m
//  手势解锁2
//
//  Created by 伍银荣 on 2021/7/8.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "ViewController.h"
#import "BtnView.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet BtnView *btnView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //设置view的背景颜色,使用平铺图片来填充颜色
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgImage"]];
    
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 200) * 0.5, 50, 200, 200)];
    [self.view addSubview:imgView];
    
    __weak typeof(self) weakSelf = self;
    self.btnView.passwordBlock = ^(BOOL res) {
        imgView.image = nil;
        //开启图片类型的图形上下文
        UIGraphicsBeginImageContextWithOptions(weakSelf.view.frame.size, NO, 0);
        //获取图形上下文
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        //截图,渲染
        [weakSelf.view.layer renderInContext:ctx];
        //获取图片
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        
        //关闭图片类型的图形上下文
        UIGraphicsEndImageContext();
        imgView.image = image;
        //UIImageWriteToSavedPhotosAlbum(image, NULL, NULL, NULL);
        if (res) {
            NSLog(@"密码正确");
        } else {
            NSLog(@"密码错误");
        }
    };
    
   
}


@end
